//
//  PlayViewController.m
//  MPFindPart
//
//  Created by xalo on 16/5/6.
//  Copyright © 2016年 马鹏. All rights reserved.
//

#import "PlayViewController.h"

@interface PlayViewController ()
@property (strong,nonatomic)UIWebView *webView;
@end

@implementation PlayViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"播放界面";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(back:)];
    
}
- (void)viewWillAppear:(BOOL)animated{
    
    [self loadWebView];
    [self.view addSubview:self.webView];
}

//返回按钮的回调方法
- (void)back:(UIBarButtonItem *)sender{
    
    [self dismissViewControllerAnimated:YES completion:nil];
}
//加载网页
- (void)loadWebView{
    
    if (self.model.youku && self.model.youku.length != 0) {
        
        [self loadWebViewWithString:self.model.youku];
        
    }else if (self.model.huashu && self.model.huashu.length != 0){
        
        [self loadWebViewWithString:self.model.huashu];
    }else if (self.model.leshi && self.model.leshi.length != 0){
        
        [self loadWebViewWithString:self.model.leshi];
    }else if (self.model.qiyi && self.model.qiyi.length != 0){
        
        [self loadWebViewWithString:self.model.qiyi];
    }else if (self.model.qq && self.model.qq.length != 0){
        
        [self loadWebViewWithString:self.model.qq];
    }else if (self.model.sohu && self.model.sohu.length != 0){
        
        [self loadWebViewWithString:self.model.sohu];
    }else if (self.model.baofeng && self.model.baofeng.length != 0){
        
        [self loadWebViewWithString:self.model.baofeng];
    }else if (self.model.pptv && self.model.pptv.length != 0){
        
        [self loadWebViewWithString:self.model.pptv];
    }else{
        
        [self showAlertViewWithMessage:@"没有播放信息"];
    }
}

//弹出警示框的方法
- (void)showAlertViewWithMessage:(NSString *)message{
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:action];
    [self presentViewController:alertController animated:YES completion:nil];
}

//根据网址加载信息
- (void)loadWebViewWithString:(NSString *)string{
    
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:string]];
    [self.webView loadRequest:request];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UIWebView *)webView{
    
    if (!_webView) {
        
        _webView = [[UIWebView alloc] initWithFrame:self.view.frame];
        _webView.scalesPageToFit = YES;
        
    }
    return _webView;
}
@end
